<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Test extends MY_Controller {

	function __construct() {
		parent::__construct();
		$this->load->model('photo_model', '', true);
		
	}
	
	function index() {
		$data = $this->photo_model->get_table_fields();
		$data = implode(', ', $data);
		echo $data;
	}
	
	function test_time() {
		echo date('Y/m/d h:m:s A', 1999999999);//1314670665
		
	}
	
	function session() {
		echo "<pre>";
		//print_r($this->session->userdata(SESSION_SOCIETY_LOGO_THUMB));
		print_r($_SESSION);
	}
	
	function read_constants() {
		$this->load->helper('file');
		$path = $_SERVER['DOCUMENT_ROOT'] . "/" . SYSTEM_FOLDER . "/application/config/constants.php";
		$string = read_file($path);
		
		$str_pattern = "/define\('SITE_NAME_FULL', '(.*?)'\);/";
		preg_match($str_pattern, $string, $result);
		print_r($result);
	}
	
	function read_csft() {
		$this->load->helper('file');
		$path = $_SERVER['DOCUMENT_ROOT'] . "/" . SYSTEM_FOLDER . "/coreseek/etc/csft.conf";
		$string = read_file($path);
		
		$str_pattern = "/sql_host = (.*)/";
		preg_match($str_pattern, $string, $result);
		print_r($result);
		
		//$str = preg_quote("\$db['default']['hostname'] = 'localhost';");
		//echo $str;
	}
	
	function rename_folder() {
		$file = $_SERVER['DOCUMENT_ROOT'] . "/" . SYSTEM_FOLDER . "/application/controllers/slll";
		$rename = $_SERVER['DOCUMENT_ROOT'] . "/" . SYSTEM_FOLDER . "/application/controllers/sl";
		if (rename($file, $rename)) { 
			echo ""; 
		} else { 
			echo ""; 
		}
	}
	
	function read_news_img() {
		$this->load->helper('file');
		$path = $_SERVER['DOCUMENT_ROOT'] . "/" . SYSTEM_FOLDER . "/news.txt";
		$string = read_file($path);
		
		$str_pattern = "/<img alt=\"\" src=\"(.*)\" \/>/";
		preg_match($str_pattern, $string, $result);
		//preg_match_all($str_pattern, $string, $result);
		
		echo "<pre>";
		print_r($result);
	}
	
	function info() {
		echo "<pre>";
		print_r(phpinfo());
	}
	
	function path() {
		echo base_url();
		echo "<pre>";
		print_r($_SERVER);
		echo "<br />";
		print_r($_COOKIE);
	}
	
	function read_xml() {
		$this->load->helper('file');
		$path = $_SERVER['DOCUMENT_ROOT'] . "/" . SYSTEM_FOLDER . "/js/plugin/piecemaker/piecemaker.xml";
		$string = read_file($path);
		
		$str_pattern = "/<Image Id=\"society_festival\" Source=\"(.*)\" Title=\"(.*)\"><Text>(.*)<\/Text><Hyperlink URL=\"(.*)\" Target=\"_blank\" \/><\/Image>/";
		preg_match($str_pattern, $string, $result);
		//preg_match_all($str_pattern, $string, $result);
		
		echo "<pre>";
		print_r($result);
	}
	
	function replace() {
		$str = '199139';
		$par = "/[\x80-\xff]/";
		echo preg_replace($par,"",$str);
	}

	function test_md5() {
		$string = "9352";
		echo md5($string);
		echo "<br />";
		echo sha1($string);
	}
	
	function test_download() {
		$this->load->helper('file');
		$this->load->helper('download');
		$data = 'Here is some text!';
		$name = 'mytext.sql';
		force_download($name, $data);
	}
	
	function test_cookie() {
		$temp = urldecode("7835d0e87f1e89dba619719c4f96bf9b%3A271094efaf67b60f7b3b851814f2d453");
		echo $temp;
	}
	
	
	function standardize_for_duoduo_zbm_code_table() {
		$this->load->helper('file');
		$path = 'D:\duoduo_zbm\code_table_files\ZBM.DIC';
		$string = read_file($path);

		$str_pattern = "/([a-z]*) \s+ ([\xa1-\xff\x80-\xff ]*)/";
		preg_match_all($str_pattern, $string, $result);
		
		list($temp1, $temp2, $temp3) = $result;
		
		foreach ($temp3 as $k => &$v) {
			if (strrpos($v, ' ')) {
				$temp_array = explode(' ', $v);
				$temp_array_2 = array();
				$temp_array_2 = array_pad($temp_array_2, count($temp_array), $temp2[$k]);
				
				array_splice($temp3, $k, 1, $temp_array);
				array_splice($temp2, $k, 1, $temp_array_2);
			}
		}
		//echo "<pre>";
		//print_r($temp2);
		//print_r($temp3);
		
		
		$standard_code_table = array();
		for ($i = 0; $i < count($temp2); $i++) {
			$standard_code_table[$i] = $temp3[$i] . '	' . $temp2[$i];
		}
		
		$code_table_template_path = 'D:\duoduo_zbm\code_table_files\code_table_template.txt';
		$code_table_path = 'D:\duoduo_zbm\code_table_files\code_table.txt';
		copy($code_table_template_path, $code_table_path);
		
		$standard_code_table_str = implode('
', $standard_code_table);
		
		$standard_code_table_str = mb_convert_encoding($standard_code_table_str, 'UCS-2LE');
		
		$fp = fopen($code_table_path, 'a+');
		if (fwrite($fp, $standard_code_table_str)) {
			echo 'succeed';
		}
		fclose($fp);
	}
	
	
	function standardize_for_duoduo_zbm_danzi() {
		$this->load->helper('file');
		$path = 'D:\duoduo_zbm\code_table_files\ZBM(danzi).DIC';
		$string = read_file($path);

		$str_pattern = "/([a-z]*) \s+ ([\xa1-\xff\x80-\xff ]*)/";
		preg_match_all($str_pattern, $string, $result);
		
		list($temp1, $temp2, $temp3) = $result;
		
		
		foreach ($temp3 as $k => &$v) {
			if (strrpos($v, ' ')) {
				$temp_array = explode(' ', $v);
				$temp_array_2 = array();
				$temp_array_2 = array_pad($temp_array_2, count($temp_array), $temp2[$k]);
				
				array_splice($temp3, $k, 1, $temp_array);
				array_splice($temp2, $k, 1, $temp_array_2);
			}
		}
		//echo "<pre>";
		//print_r($temp2);
		//print_r($temp3);
		
		
		$standard_danzi = array();
		for ($i = 0; $i < count($temp2); $i++) {
			$standard_danzi[$i] = $temp3[$i] . '	' . $temp2[$i];
		}
		
		$danzi_template_path = 'D:\duoduo_zbm\code_table_files\danzi_template.txt';
		$danzi_path = 'D:\duoduo_zbm\code_table_files\danzi.txt';
		copy($danzi_template_path, $danzi_path);
		
		$standard_danzi_str = implode('
', $standard_danzi);
		
		$standard_danzi_str = mb_convert_encoding($standard_danzi_str, 'UCS-2LE');
		
		$fp = fopen($danzi_path, 'a+');
		if (fwrite($fp, $standard_danzi_str)) {
			echo 'succeed';
		}
		fclose($fp);
	}
	
	function exchange_encode() {
		$this->load->helper('file');
		$path = 'C:\wamp\www\neusal\index.php.exchange';
		$string = read_file($path);
		//echo mb_check_encoding($string);
		echo mb_detect_encoding($string);
	}
	
}